/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
function Ajax(){
    xmlhttp=false;
    this.encodeURIString = true;
    this.execute = false;
    if (window.XMLHttpRequest) {
        this.xmlhttp = new XMLHttpRequest();
        if (this.xmlhttp.overrideMimeType) {
            this.xmlhttp.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject) {
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                this.xmlhttp = null;
            }
        }
        if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
            this.xmlhttp = new XMLHttpRequest();
            if (!this.xmlhttp){
                this.failed = true;
            }
        }
    }
    return this.xmlhttp;
}

function procesaPost(destino,parametros,mensaje,div){
    var ajax=Ajax();
    var capaContenedora=document.getElementById(div);
    ajax.open ('POST',destino, true);
    ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajax.setRequestHeader("Content-length", parametros.length);
    ajax.setRequestHeader("Connection", "close");

    ajax.onreadystatechange = function() {
        if (ajax.readyState==1) {
            capaContenedora.innerHTML="<b><font face='Arial' size='2'>"+mensaje+"</font></b>";
        }
        else if (ajax.readyState==4){
            if(ajax.status==200){
                capaContenedora.innerHTML=ajax.responseText;
            }
            else if(ajax.status==404){
                capaContenedora.innerHTML = "<center><b><font face='Arial' size='2'>La direcci&oacute;n no existe.</font></b></center>";
            }
            else{
                capaContenedora.innerHTML = "Error: "+ajax.status;
            }
        }
    }
    ajax.send(parametros);
}

function doAjaxJavaScript(origen,destino) {
    $.ajax({
        url: origen,
        context: document.body,
        success: function(responseText) {
            $("#"+destino).html(responseText);
            $("#"+destino).find("script").each(function(i) {
                eval($(this).text());
            });
        }
    });
};







